package com.cjl.food.controller.v1;

import com.cjl.common.dtos.PageDto;
import com.cjl.common.dtos.ResponseResult;
import com.cjl.food.dtos.FoodDto;
import com.cjl.food.service.FoodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author cjl
 * @version v1.0
 * @description TODO
 * @createTime 2023/2/16 14:44
 */

@RestController
@Api(value = "FoodController", description = "菜品控制层，菜品的crud")
@RequestMapping("/api/food")
    public class FoodController {


    @Autowired
    FoodService foodService;

    @ApiOperation("添加菜品")
    @PostMapping("addFood")
    public ResponseResult addFood(@RequestBody FoodDto foodDto) {
        return foodService.addFood(foodDto);
    }

    @ApiOperation("根据菜名删除菜品")
    @GetMapping("deleteFood")
    public ResponseResult deleteFood(@RequestParam("foodName") String foodName) {
        return foodService.deleteFood(foodName);
    }


    @ApiOperation("修改菜品")
    @PostMapping("modifyFood")
    public ResponseResult modifyFood(@RequestBody FoodDto foodDto) {
        return foodService.modifyFood(foodDto);
    }


    @ApiOperation("根据菜名查询菜品")
    @GetMapping("searchFood")
    public ResponseResult searchFood(@RequestParam("foodName") String foodName) {
        return foodService.searchFood(foodName);
    }

    @ApiOperation("菜品列表")
    @PostMapping("foodList")
    public ResponseResult foodList(@RequestBody PageDto pageDto) {
        return foodService.foodList(pageDto);
    }


    @ApiOperation("根据id获取菜品")
    @GetMapping("getFoodById")
    public ResponseResult getFoodById(@RequestParam("foodId") Integer foodId) {
        return foodService.getFoodById(foodId);
    }

}
